package traveldream.ejb.sessionBean;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import traveldream.ejb.DTO.TransportationDTO;
import traveldream.ejb.entities.TransportationMean;
import traveldream.ejb.interfaces.TransportInsertBeanLocal;

/**
 * Session Bean implementation class TransportInsertBean
 */
@Stateless
public class TransportInsertBean implements TransportInsertBeanLocal {

	@PersistenceContext
	private EntityManager em;
	
	
    /**
     * Default constructor. 
     */
    public TransportInsertBean() {
        // TODO Auto-generated constructor stub
    }
    
    public boolean checkCity(TransportationDTO tDTO){
    	return tDTO.getDeparturePlace().equals(tDTO.getArrivalPlace());
    }
    
    public boolean checkDate(TransportationDTO tDTO){
    	if(tDTO.getDepartureDate().equals(tDTO.getArrivalDate())){
    		return tDTO.getDepartureTime().compareTo(tDTO.getArrivalTime()) < 0;
    	}
    	return tDTO.getDepartureDate().compareTo(tDTO.getArrivalDate()) < 0;
    }

	@Override
	public void insert(TransportationDTO tDTO) {
		// TODO Auto-generated method stub
		em.persist(new TransportationMean(tDTO));
	}

}
